/*     */ package com.zimbra.cs.fb;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.Element.XMLElement;
/*     */ import com.zimbra.common.soap.SoapHttpTransport;
/*     */ import com.zimbra.cs.httpclient.URLUtil;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.Date;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class FbCli
/*     */ {
/*     */   private SoapHttpTransport mTransport;
/*     */   
/*     */   public static class FbProvider
/*     */   {
/*     */     public String name;
/*     */     public boolean propagate;
/*     */     public String queue;
/*     */     public String prefix;
/*     */     public long fbstart;
/*     */     public long fbend;
/*     */     
/*     */     public String toString()
/*     */     {
/*  42 */       StringBuilder buf = new StringBuilder();
/*  43 */       buf.append(this.name).append("\n");
/*  44 */       buf.append("\t").append("propagate: ").append(this.propagate).append("\n");
/*  45 */       buf.append("\t").append("queue:     ").append(this.queue).append("\n");
/*  46 */       buf.append("\t").append("prefix:    ").append(this.prefix).append("\n");
/*  47 */       buf.append("\t").append("start:     ").append(new Date(this.fbstart)).append("\n");
/*  48 */       buf.append("\t").append("end:       ").append(new Date(this.fbend)).append("\n");
/*  49 */       return buf.toString();
/*     */     }
/*     */   }
/*     */   
/*     */   public static class FbQueue { public String name;
/*     */     Collection<String> accounts;
/*     */     
/*  56 */     public FbQueue() { this.accounts = new ArrayList(); }
/*     */     
/*     */     public String toString() {
/*  59 */       StringBuilder buf = new StringBuilder();
/*  60 */       buf.append(this.name).append("\n");
/*  61 */       for (String acct : this.accounts) {
/*  62 */         buf.append("\t").append(acct).append("\n");
/*     */       }
/*  64 */       return buf.toString();
/*     */     }
/*     */   }
/*     */   
/*  68 */   public FbCli() throws ServiceException { setServer(LC.zimbra_zmprov_default_soap_server.value()); }
/*     */   
/*     */   public void setServer(String server)
/*     */   {
/*  72 */     String adminUrl = URLUtil.getAdminURL(server);
/*  73 */     this.mTransport = new SoapHttpTransport(adminUrl);
/*     */   }
/*     */   
/*     */   public Collection<FbProvider> getAllFreeBusyProviders() throws ServiceException, IOException {
/*  77 */     ArrayList<FbProvider> providers = new ArrayList();
/*     */     try {
/*  79 */       auth();
/*  80 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_ALL_FREE_BUSY_PROVIDERS_REQUEST);
/*  81 */       Element resp = this.mTransport.invoke(req);
/*  82 */       for (Element provElem : resp.listElements("provider")) {
/*  83 */         FbProvider prov = new FbProvider();
/*  84 */         prov.name = provElem.getAttribute("name", null);
/*  85 */         prov.propagate = provElem.getAttributeBool("propagate", false);
/*  86 */         prov.fbstart = provElem.getAttributeLong("start", 0L);
/*  87 */         prov.fbend = provElem.getAttributeLong("end", 0L);
/*  88 */         prov.queue = provElem.getAttribute("queue", null);
/*  89 */         prov.prefix = provElem.getAttribute("prefix", null);
/*  90 */         providers.add(prov);
/*     */       }
/*     */     } finally {
/*  93 */       this.mTransport.shutdown();
/*     */     }
/*  95 */     return providers;
/*     */   }
/*     */   
/*     */   public Collection<FbQueue> getFreeBusyQueueInfo(String provider) throws ServiceException, IOException {
/*  99 */     ArrayList<FbQueue> queues = new ArrayList();
/*     */     try {
/* 101 */       auth();
/* 102 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_FREE_BUSY_QUEUE_INFO_REQUEST);
/* 103 */       if (provider != null)
/* 104 */         req.addElement("provider").addAttribute("name", provider);
/* 105 */       Element resp = this.mTransport.invoke(req);
/* 106 */       for (Element provElem : resp.listElements("provider")) {
/* 107 */         FbQueue queue = new FbQueue();
/* 108 */         queue.name = provElem.getAttribute("name", null);
/* 109 */         for (Element acctElem : provElem.listElements("account")) {
/* 110 */           queue.accounts.add(acctElem.getAttribute("id", null));
/*     */         }
/* 112 */         queues.add(queue);
/*     */       }
/*     */     } finally {
/* 115 */       this.mTransport.shutdown();
/*     */     }
/* 117 */     return queues;
/*     */   }
/*     */   
/*     */   public void pushFreeBusyForDomain(String domain) throws ServiceException, IOException {
/*     */     try {
/* 122 */       auth();
/* 123 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.PUSH_FREE_BUSY_REQUEST);
/* 124 */       req.addElement("domain").addAttribute("name", domain);
/* 125 */       this.mTransport.invoke(req);
/*     */     } finally {
/* 127 */       this.mTransport.shutdown();
/*     */     }
/*     */   }
/*     */   
/*     */   public void pushFreeBusyForAccounts(Collection<String> accounts) throws ServiceException, IOException {
/*     */     try {
/* 133 */       auth();
/* 134 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.PUSH_FREE_BUSY_REQUEST);
/* 135 */       for (String acct : accounts)
/* 136 */         req.addElement("account").addAttribute("id", acct);
/* 137 */       this.mTransport.invoke(req);
/*     */     } finally {
/* 139 */       this.mTransport.shutdown();
/*     */     }
/*     */   }
/*     */   
/*     */   public void purgeFreeBusyQueue(String provider) throws ServiceException, IOException {
/*     */     try {
/* 145 */       auth();
/* 146 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.PURGE_FREE_BUSY_QUEUE_REQUEST);
/* 147 */       if (provider != null)
/* 148 */         req.addElement("provider").addAttribute("name", provider);
/* 149 */       this.mTransport.invoke(req);
/*     */     } finally {
/* 151 */       this.mTransport.shutdown();
/*     */     }
/*     */   }
/*     */   
/*     */   private void auth() throws ServiceException, IOException {
/* 156 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
/* 157 */     req.addElement("name").setText(LC.zimbra_ldap_user.value());
/* 158 */     req.addElement("password").setText(LC.zimbra_ldap_password.value());
/* 159 */     Element resp = this.mTransport.invoke(req);
/* 160 */     this.mTransport.setAuthToken(resp.getElement("authToken").getText());
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/fb/FbCli.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */